package com.GainLoop;

import com.GainLoop.Api.Tags;
import com.GainLoop.Api.Entity.Tag;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class GainSearch extends Activity{
	
	private static final String[] TAGS = new String[]{"cool","work","israel"}; //TODO : remove in future-Meir
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.gain_search);
	        
	      //adding tags
	        Tags tags = new Tags();
	        //TODO : need an api for getting all tags... - Meir
	   
	        AutoCompleteTextView tagsRow = (AutoCompleteTextView) findViewById(R.id.search_gain_autocomplete_tags);
	        ArrayAdapter<String> tagsAdapter = new ArrayAdapter<String>(this, R.layout.list_item, TAGS);//TODO : need to replace TAGS, with tags from server - Meir
	        tagsRow.setAdapter(tagsAdapter);
	        TextView addedTags = (TextView) findViewById(R.id.search_gain_added_tag);
	        
	        Button addTagButton = (Button) findViewById(R.id.search_gain_add_tag_button);
	        //TODO - need to see how to add tags in a more elegant way.. - Meir
	        addTagButton.setOnClickListener(new tagButtonListener(addedTags,tagsRow,getApplicationContext()));
	        
	 }
	 
	 public boolean onCreateOptionsMenu(Menu menu) {
	        MenuInflater inflater = getMenuInflater();
	        inflater.inflate(R.menu.menu, menu);
	        menu.setGroupVisible(R.id.group1, false);
	        menu.setGroupVisible(R.id.group2, false);
	        menu.setGroupVisible(R.id.group3, false);
	        
	        menu.setGroupVisible(R.id.groupSearch, false);
	        
	        return true;
	    }
	    public boolean onOptionsItemSelected (MenuItem item){
	    	Toast toast;
	    	Intent intent;
			 switch (item.getItemId()) {
			    case R.id.menu_profile_button:
			    	intent=new Intent(GainSearch.this,UserPage.class);
			    	GainSearch.this.startActivity(intent);
			        return true;
			    case R.id.help_button:
			    	toast = Toast.makeText(GainSearch.this,"help", Toast.LENGTH_LONG);
					toast.show();
			        return true; 
			    case R.id.menu_search_button:
			    	intent=new Intent(GainSearch.this,GainSearch.class);
			    	GainSearch.this.startActivity(intent);
			        return true;
			    case R.id.menu_new_gain_button:
			    	intent=new Intent(GainSearch.this,AddRequest.class);
			    	GainSearch.this.startActivity(intent);
			        return true;   
			    case R.id.menu_home_button:
			    	intent=new Intent(GainSearch.this,Home.class);
			    	GainSearch.this.startActivity(intent);
			        return true; 
			        
			    default:
			        return super.onOptionsItemSelected(item);
			    }
			
	    }
}
